package com.proj.hot.widget;


import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

import com.proj.hot.R;


public class XWDialog_yes extends Dialog {
	 public interface OnCustomDialogListener{
         public void back(String name);
 }



    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            // TODO Auto-generated method stub
            switch (msg.what) {

                case 1:
                    if (count>-1){

                        okBtn.setText(btnTxt+"("+count+")");
                        mHandler.sendEmptyMessageDelayed(1,1000);
                        count--;
                    }else{
                        dismiss();
                    }

                    break;


                default:
                    break;
            }
        }

    };




 private OnCustomDialogListener customDialogListener;
 TextView TV;
 String title;
    int count=0;
    Button okBtn;
    String btnTxt;

 public XWDialog_yes(Context context, String title, boolean Cancel, OnCustomDialogListener onCustomDialogListener) {
	 super(context, R.style.mydialog);
	     this.title=title;
         this.customDialogListener = onCustomDialogListener;
         this.requestWindowFeature(Window.FEATURE_NO_TITLE);
     setCancelable(Cancel);

        
 }


    public  void setTimeDisminss(int count,String btnTxt){
        this.count=count;
        this.btnTxt=btnTxt;
        mHandler.sendEmptyMessageDelayed(1,0);
    }


 @Override
 protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.update_view_dialogyes);
         //设置标题
//         setTitle(name);
         TV=(TextView) findViewById(R.id.title);
         TV.setText(title);
     okBtn=(Button)findViewById(R.id.btn1);
     okBtn.setOnClickListener(clickListener);
//         findViewById(R.id.btn2).setOnClickListener(clickListener);
         setCanceledOnTouchOutside(true);
 }

 private View.OnClickListener clickListener = new View.OnClickListener() {
        
         @Override
         public void onClick(View v) {
        	 System.out.println("OnClickListener");
        	 if (v.getId()==R.id.btn1) {
        		 customDialogListener.back("0");
        		 
			}
        	 XWDialog_yes.this.dismiss();
         }
 };

 
 
 
 
}
